package cn.walls1717.ggkt.live.api;

import cn.walls1717.ggkt.live.service.LiveCourseService;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.util.AuthContextHolder;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 前台观看直播相关接口
 *
 * @author walls1717
 * @since 2022/7/24
 **/
@Api(tags = "前台观看直播相关接口")
@RestController
@RequestMapping("api/live/liveCourse")
public class LiveCourseApiController {

    @Autowired
    private LiveCourseService liveCourseService;

    @ApiOperation("获取用户access_token")
    @GetMapping("getPlayAuth/{id}")
    public Result<JSONObject> getPlayAuth(@PathVariable Long id) {
        JSONObject object = liveCourseService.getPlayAuth(id, AuthContextHolder.getUserId());
        return Result.success(object);
    }

    @ApiOperation("根据ID查询课程")
    @GetMapping("getInfo/{courseId}")
    public Result<Map<String, Object>> getLiveCourseInfoByCourseId(@PathVariable Long courseId){
        Map<String, Object> map = liveCourseService.getLiveCourseInfoByCourseId(courseId);
        return Result.success(map);
    }
}
